﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DupeKill.Core.Comparison
{
    internal class ByLengthFileSetComparer : IFileSetComparer 
    {
        #region IFileSetComparer Member

        public IEnumerable<FileSet> CompareAndSplit(FileSet fileSet)
        {
            if (fileSet == null)
                throw new ArgumentNullException();

            Dictionary<long, FileSet> byLength = new Dictionary<long, FileSet>();

            for (int i = 0; i < fileSet.Count; i++)
            {
                FileInformation info = fileSet[i];

                FileSet target;

                if (!byLength.TryGetValue(info.Length, out target))
                {
                    target = new FileSet();
                    byLength.Add(info.Length, target); 
                }

                target.Add(info); 
            }

            return byLength.Values; 
        }

        #endregion
    }
}
